package com.parkreport.admin.user.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.common.base.BaseServlet;
import com.common.util.StringUtil;
import com.parkreport.admin.parkarea.service.ParkAreaService;
import com.parkreport.admin.user.service.UserService;
import com.parkreport.vo.ParkArea;
import com.parkreport.vo.Roles;
import com.parkreport.vo.UsersVO;

public class UserServlet extends BaseServlet {

	private UserService service = new UserService();
	private ParkAreaService parkService = new ParkAreaService();
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		this.req=req;
		this.res=res;
		
		String method = req.getParameter("method");
		
		if("find".equalsIgnoreCase(method)){
			find();
		}else if("edit".equalsIgnoreCase(method)){
			edit();
		}else if("save".equalsIgnoreCase(method)){
			save();
		}else if("delete".equalsIgnoreCase(method)){
			delete();
		}else{
			find();
		}
		
	}
	private void find() throws ServletException, IOException{
		UsersVO vo = new UsersVO();
		
		//List<UsersVO> list = service.find(vo);
		
		//req.setAttribute("list", list);
		
		req.getRequestDispatcher("../pages/admin/user/list.jsp").forward(req, res);
		
	}
	private void edit() throws ServletException, IOException{
		String id = req.getParameter("id");
		UsersVO vo = new UsersVO();
		if(StringUtil.isBlank(id)){
			vo = service.get(id);
			req.setAttribute("vo", vo);
		}
		
		List<ParkArea> parkAreaList = parkService.find();
		List<Roles> roleList = service.findRole();
		req.setAttribute("parkAreaList", parkAreaList);
		req.setAttribute("roleList", roleList);
		req.getRequestDispatcher("../pages/admin/user/edit.jsp").forward(req, res);
		
	}
	private void save(){
		
	}
	private void delete(){
		
	}
	
}
